﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using DAL.SQLStatements;
using BAL.Entities;
using BAL.Utils;

namespace DAL.LogicComponents
{
    public class clsFuelDAL
    {
        #region --- Get All Fuel
        public static DataTable doFuelSelectList()
        {
            // Select all of products by user id
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblFuel";
            query.propColumn = "*";
            query.propWhere = "FuelID > 0" + " order by Fuel";

            // return result
            return query.getDatatable();
        }
        #endregion

        #region --- Get All Fuel by id
        public static DataTable doFuelSelectListById(clsFuel obj)
        {
            // Select all of products by user id
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblFuel";
            query.propColumn = "*";
            query.propWhere = "FuelID = '"+obj.FuelID+"'";

            // return result
            return query.getDatatable();
        }
        #endregion

        #region -- add Fuel
        public static bool queryAddFuel(clsFuel obj)
        {
            // Add value to column(s)
            Dictionary<String, Object> data = new Dictionary<String, Object>();
            data.Add("Fuel", "N'" + obj.FuelName+ "'");
            data.Add("colDescription", "N'" + obj.Description + "'");
            data.Add("InsertDate", "'"+clsDateTimeSetting.UTCTime()+"'");

            //Execute insert query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeInsertInto("tblFuel", data);
        }
        #endregion

        #region --- Update Fuel
        public static bool queryUpdateFuel(clsFuel obj)
        {
            Dictionary<String, Object> cols = new Dictionary<String, Object>();
            cols.Add("Fuel", "N'" + obj.FuelName+ "'");
            cols.Add("colDescription", "N'" + obj.Description + "'");
            cols.Add("LastUpdate","'"+ clsDateTimeSetting.UTCTime() +"'");
            // Execute update query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeUpdate("tblFuel", cols, String.Format("FuelID = {0}", obj.FuelID));

        }
        #endregion

        #region -- check Fuel Exist
        public static bool CheckFuelExist(clsFuel obj)
        {
            clsQueryBuilder query = new clsQueryBuilder();
            query.propColumn = "Fuel";
            query.propTable = "tblFuel";
            query.propWhere = "FuelID > 0 and Fuel = N'" + obj.FuelName + "'";

            return query.getBoolValue();
        }
        #endregion
    }
}